package ui;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import java.util.Vector;

public class GetConnectionTypeScreen extends Form implements CommandListener {
	private manager.AgentManagerMIDlet midlet;
    private final Command exitCommand;
    private final Command confirmCommand;
    private final Display display;
    private TextField textField;
    private Vector dests;
    private Vector startTimes;
    private Vector endTimes;
    private int meetingLength;
    
	public GetConnectionTypeScreen(manager.AgentManagerMIDlet midlet,
									Display display,
									Vector dests,
									Vector startTimes,
									Vector endTimes,
									int meetingLength){
		super("Please enter the connection type");
		this.midlet = midlet;
		this.display = display;
		this.dests = dests;
		this.startTimes = startTimes;
		this.endTimes = endTimes;
		this.meetingLength = meetingLength;
        confirmCommand = new Command("Confirm", Command.SCREEN,1);
        exitCommand = new Command("Exit", Command.EXIT, 1);
        this.addCommand(confirmCommand);
        this.addCommand(exitCommand);
		textField = new TextField("Please Enter connection type : ('D' for datagram, 'S' for Socket)",
									"",
									1,
									TextField.ANY);
		this.append(textField);
		this.setCommandListener(this);
	}
	
	public void commandAction(Command c, Displayable d) {
        if (c == exitCommand)
        {
            midlet.exitRequested();
        }else if(c == confirmCommand){
        	if(textField.getString().equals("D")){
        		midlet.getIOHandlerManager().createMeetingAgent(dests,startTimes,endTimes,meetingLength,"D");
        	}else if(textField.getString().equals("S")){
        		midlet.getIOHandlerManager().createMeetingAgent(dests,startTimes,endTimes,meetingLength,"S");
        	}
        }
	}

}
